PROJECT ( get6dtraj )

MESSAGE (STATUS "\n***************** Configuring ${PROJECT_NAME} *****************")

cmake_minimum_required(VERSION 3.10.2)
CMAKE_POLICY(VERSION 2.6)

GET_FILENAME_COMPONENT (CurrentPath ${CMAKE_CURRENT_LIST_FILE} PATH)

#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")

# search for MMMCore
FIND_PACKAGE(MMMCore REQUIRED)

# search for simox
FIND_PACKAGE(Simox REQUIRED)

SET(get6dtraj_BASE_DIR ${PROJECT_SOURCE_DIR} CACHE INTERNAL "" )

ADD_DEFINITIONS(-Dget6dtraj_BASE_DIR="${get6dtraj_BASE_DIR}" -D_SCL_SECURE_NO_WARNINGS)

IF(MMMCore_FOUND AND Simox_USE_COIN_VISUALIZATION)
    # setup Simox include paths and libraries

    ADD_DEFINITIONS(-DMMMTools_LIB_DIR="${MMMTools_LIB_DIR}")

	INCLUDE_DIRECTORIES(${MMMCORE_INCLUDE_DIRS})

	INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/../3rdParty")
	INCLUDE_DIRECTORIES("${PROJECT_SOURCE_DIR}/../MMMSimoxTools")
	
	########## OS specific setup (including rpath)    
	IF(UNIX)
		# We are on Linux
		IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
			ADD_DEFINITIONS(-fPIC)
		ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
		MESSAGE (STATUS " * BUILDTYPE: ${CMAKE_BUILD_TYPE}")
		
		# use, i.e. don't skip the full RPATH for the build tree
		SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
	
		# when building, don't use the install RPATH already
		# (but later on when installing)
		SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) 
	   
		# add the automatically determined parts of the RPATH
		# which point to directories outside the build tree to the install RPATH
		SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
	
		# the RPATH to be used when installing, but only if it's not a system directory
		LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${INSTALL_LIB_DIR}" isSystemDir)
		IF("${isSystemDir}" STREQUAL "-1")
		   #MESSAGE("INSTALL RPATH MMMSimoxToolsLibDir: ${INSTALL_LIB_DIR}" )
		   SET(CMAKE_INSTALL_RPATH "${INSTALL_LIB_DIR}")
		ENDIF("${isSystemDir}" STREQUAL "-1")
		SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_RPATH}" "${MMMCore_LIB_DIRS}")
		#MESSAGE ("CMAKE_INSTALL_RPATH: ${CMAKE_INSTALL_RPATH}")
                #UNIX needs to link the dynamic library lib (dl)
                SET(DL_LIB dl)
        ELSE(UNIX)
		# We are on Windows
		ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)
		
		# On MSVC we compile with /MP flag (use multiple threads)
		IF(MSVC)
			ADD_DEFINITIONS(/MP)
		ENDIF(MSVC)
	ENDIF(UNIX)
	
        ADD_EXECUTABLE(get6dtraj get6dtraj.cpp)
	
    TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${MMMCORE_LIBRARIES} VirtualRobot MMMSimoxTools ${DL_LIB})

	SET (get6dtrajLibDir ${CMAKE_BINARY_DIR}/lib)
	SET (get6dtrajBinDir ${CMAKE_BINARY_DIR}/bin)

	# .DLL path
	SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${get6dtrajBinDir})
	# .so path
	SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${get6dtrajLibDir})
	# .lib path (this is needed for setting the DLL-import library path on windows)
	SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${get6dtrajLibDir})
	
	# setup installation 
    install(TARGETS ${PROJECT_NAME}
		# IMPORTANT: Add executable to the "export-set"
		EXPORT MMMToolsTargets
		RUNTIME DESTINATION "${INSTALL_BIN_DIR}" COMPONENT bin)

ELSE()
    MESSAGE ("Simox was not compiled with Coin3D/Qt support") 
ENDIF()


MESSAGE (STATUS "***************** Finished Configuring ${PROJECT_NAME} *****************\n")

